var app = getApp(), fabu = require("../utils/util.js"), siteinfo = require("../../../siteinfo.js");

Page({
    data: {
        array: [ "线上活动", "线下活动" ],
        index_class: 0,
        index: 0,
        city_index: 0,
        fabufoot: !0,
        tempFilePaths: "",
        icon: !0
    },
    onLoad: function(t) {
        var a = this, e = wx.getStorageSync("db_tab"), i = app.contains(e, "../logs/logs");
        console.log(i), a.setData({
            db_tab: e
        });
        try {
            wx.removeStorageSync("bminfo"), wx.removeStorageSync("mode");
        } catch (t) {}
        wx.hideShareMenu(), a.setData({
            today: app.util.time()
        }), null == t.id ? a.setData({
            edit: !1
        }) : (app.util.request({
            url: "entry/wxapp/ActivityDetails",
            data: {
                activity_id: t.id
            },
            success: function(t) {
                console.log(t), 1 == t.data.activity_type ? t.data.activity_type = "线上活动" : t.data.activity_type = "线下活动", 
                a.setData({
                    address: t.data.address,
                    link_tel: t.data.link_tel,
                    datastart: app.ormatDate(t.data.start_time).slice(0, 10),
                    time1: app.ormatDate(t.data.start_time).slice(10, 16),
                    dataend: app.ormatDate(t.data.end_time).slice(0, 10),
                    time2: app.ormatDate(t.data.end_time).slice(10, 16),
                    uplogo: t.data.logo,
                    title: t.data.title,
                    activity_type: t.data.activity_type,
                    type_id: t.data.type_id,
                    cityname: t.data.cityname,
                    hx_code: t.data.hx_code,
                    edit: !0,
                    content: t.data.content,
                    imgs: t.data.hd_imgs,
                    bm_info: t.data.bm_info,
                    coordinates: t.data.coordinates,
                    zd_money: t.data.zd_money
                });
            }
        }), a.setData({
            activity_id: t.id
        })), a.refresh();
    },
    user_info: function(t) {
        var a = this, e = wx.getStorageSync("userInfo"), i = wx.getStorageSync("userInfo").id;
        a.setData({
            user_id: i
        }), app.util.request({
            url: "entry/wxapp/GetSponsor",
            cachetime: "0",
            data: {
                user_id: i
            },
            success: function(t) {
                console.log("这是获取主办方资料"), console.log(t), 0 == t.data ? wx.showModal({
                    title: "创建主办方",
                    content: "您还没有进行填写主办方信息",
                    success: function(t) {
                        t.confirm ? (console.log("用户点击确定"), wx.navigateTo({
                            url: "../mycenter/edit?status=1"
                        })) : t.cancel && (console.log("用户点击取消"), wx.redirectTo({
                            url: "../index/index"
                        }));
                    }
                }) : (app.util.request({
                    url: "entry/wxapp/getSystem",
                    cachetime: "0",
                    success: function(t) {
                        console.log("这是系统设置"), console.log(t), 1 == t.data.is_sfrz && 0 == e.rz_type && wx.showModal({
                            title: "身份认证提示",
                            content: "您还没有进行身份认证",
                            success: function(t) {
                                t.confirm ? (console.log("用户点击确定"), wx.navigateTo({
                                    url: "../authentication/authentication"
                                })) : t.cancel && (console.log("用户点击取消"), wx.navigateBack({
                                    delta: 1
                                }));
                            }
                        });
                    }
                }), a.setData({
                    sponsor: t.data.name
                }));
            }
        });
    },
    refresh: function(t) {
        var i = this;
        app.util.request({
            url: "entry/wxapp/url",
            cachetime: "0",
            success: function(t) {
                console.log("这是网址"), console.log(t), i.setData({
                    url: t.data
                });
            }
        }), app.util.request({
            url: "entry/wxapp/typeList",
            cachetime: "0",
            success: function(t) {
                if (console.log("这是分类"), console.log(t), null != i.data.type_id) for (var a in t.data) i.data.type_id == t.data[a].id && i.setData({
                    type_name: t.data[a].type_name
                });
                var e = [];
                t.data.map(function(t) {
                    var a;
                    a = t.type_name, e.push(a);
                }), i.setData({
                    typeList: t.data,
                    classification: e
                });
            }
        }), app.getUserInfo(function(t) {
            console.log(t), i.setData({
                userInfo: t
            });
        });
    },
    icon: function(t) {
        var a = this, e = a.data.icon;
        1 == e ? a.setData({
            icon: !1
        }) : a.setData({
            icon: !0
        });
    },
    fabuimg: function(t) {
      var e = this, i = wx.getStorageSync("siteroot");
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(t) {
                var a = t.tempFilePaths[0];
                wx.uploadFile({
                  url: i + "?i=" + siteinfo.uniacid + "&c=entry&a=wxapp&do=upload&m=zh_gjhdbm",
                    filePath: a,
                    name: "upfile",
                    formData: {},
                    success: function(t) {
                        console.log(t), e.setData({
                            uplogo: t.data
                        });
                    },
                    fail: function(t) {}
                }), e.setData({
                    logo: a
                });
            }
        });
    },
    selehuodong: function(t) {
        this.setData({
            index: t.detail.value
        });
    },
    city: function(t) {
        this.setData({
            city_index: t.detail.value
        });
    },
    classification: function(t) {
        this.setData({
            index_class: t.detail.value
        });
    },
    datastart: function(t) {
        console.log("picker发送选择改变，携带值为", t.detail.value), this.setData({
            datastart: t.detail.value
        });
    },
    dataend: function(t) {
        console.log("picker发送选择改变，携带值为", t.detail.value), this.setData({
            dataend: t.detail.value
        });
    },
    bindTimeChange1: function(t) {
        console.log("picker发送选择改变，携带值为", t.detail.value), this.setData({
            time1: t.detail.value
        });
    },
    bindTimeChange2: function(t) {
        console.log("picker发送选择改变，携带值为", t.detail.value), this.setData({
            time2: t.detail.value
        });
    },
    baomingset: function() {
        wx.navigateTo({
            url: "enrollset",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    fabuinfo: function() {
        console.log(111), wx.navigateTo({
            url: "fabuinfo",
            success: function(t) {},
            fail: function(t) {},
            complete: function(t) {}
        });
    },
    addimg: function() {
        this.setData({
            fabufoot: !1
        });
    },
    address: function(t) {
        var e = this;
        wx.chooseLocation({
            success: function(t) {
                console.log(t);
                var a = t.latitude + "," + t.longitude;
                console.log(a), e.setData({
                    address: t.address,
                    coordinates: a
                });
            }
        });
    },
    link_tel: function(t) {
        console.log(t), this.setData({
            link_tel: t.detail.value
        });
    },
    identity: function(t) {
        wx.navigateTo({
            url: "../mycenter/inform?status=4"
        });
    },
    formSubmit: function(t) {
        console.log(t);
        var a = this;
        if (console.log(a.data.edit), 1 == a.data.edit) var e = a.data.content, i = a.data.imgs;
        var n = a.data.typeList, o = a.data.uplogo, s = t.detail.value.title;
        if (null == a.data.activity_type) var c = a.data.array[a.data.index]; else c = a.data.activity_type;
        if (null == a.data.type_id) {
            var l = a.data.classification[a.data.index_class];
            for (var d in n) n[d].type_name == l && (l = n[d].id);
        } else l = a.data.type_id;
        var u = wx.getStorageSync("city");
        console.log(u);
        var r = a.data.datastart, f = a.data.dataend, p = a.data.time1, m = a.data.time2, g = r + " " + p, y = f + " " + m, _ = a.data.sponsor, h = a.data.address, v = a.data.coordinates, x = a.data.link_tel, w = a.data.icon, b = t.detail.value.hx_code, D = "";
        "" == o || null == o ? D = "请上传活动海报" : "" == s ? D = "请输入活动标题" : null == c ? D = "请选择活动方式" : null == l ? D = "请选择活动分类" : null == r ? D = "请输入活动开始日期" : null == f ? D = "请输入活动结束日期" : f < r ? D = "活动开始日期不能大于活动结束日期" : null == p ? D = "请输入活动开始时间" : null == m ? D = "请输入活动结束时间" : g == y ? D = "活动开始时间不能和结束时间一致" : null == h ? D = "请选择活动地点" : null == x || "" == x ? D = "请输入联系电话" : null == b || "" == b ? D = "请输入活动核销码" : 0 == w && (D = "请阅读并同意发布须知"), 
        "" != D ? wx.showModal({
            title: "温馨提示",
            content: D,
            showCancel: !0,
            cancelText: "取消",
            cancelColor: "#333",
            confirmText: "确定",
            confirmColor: "#333"
        }) : 0 == a.data.edit ? wx.navigateTo({
            url: "enrollset?uplogo=" + o + "&title=" + s + "&array=" + c + "&classification=" + l + "&start_time=" + g + "&end_time=" + y + "&address=" + h + "&link_tel=" + x + "&coordinates=" + v + "&link_tel=" + x + "&sponsor=" + _ + "&city=" + u + "&hx_code=" + b
        }) : wx.navigateTo({
            url: "fabuinfo?uplogo=" + o + "&title=" + s + "&array=" + c + "&classification=" + a.data.type_id + "&start_time=" + g + "&end_time=" + y + "&address=" + h + "&link_tel=" + x + "&coordinates=" + v + "&link_tel=" + x + "&sponsor=" + _ + "&city=" + u + "&hx_code=" + b + "&imgs=" + i + "&content=" + e + "&activity_id=" + a.data.activity_id + "&bminfo=" + a.data.bm_info + "&zd_money=" + a.data.zd_money
        });
    },
    wode: function() {
        var t = this.data.db_tab;
        wx.reLaunch({
            url: t[3].src
        });
    },
    fabu: function() {
        wx.reLaunch({
            url: "../fabu/fabu"
        });
    },
    index: function() {
        var t = this.data.db_tab;
        wx.reLaunch({
            url: t[0].src
        });
    },
    classifination: function(t) {
        var a = this.data.db_tab;
        wx.reLaunch({
            url: a[1].src
        });
    },
    mine_activity: function(t) {
        var a = this.data.db_tab;
        wx.reLaunch({
            url: a[2].src
        });
    },
    onReady: function() {},
    onShow: function() {
        this.user_info();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {}
});